import React from 'react';
import {putInvoiceInforeate} from '../../../../api';
import { Modal, Input, Form, DatePicker, Select, InputNumber, message } from 'antd';
import moment from 'moment';

const { Option } = Select;

/**
 * @description: 开票登记 -- 开票登记弹窗
 * @author: xiaoxujs
 * @updata: xiaoxujs 2021-11-22 调取接口
 */

const AddModule = ({ setAddModuleShow, addModuleShow, clickId, conNoId }) => {
    const [form] = Form.useForm();
    const {validateFields, resetFields} = form;
    const handleOk = () => {
        validateFields().then(values => {
            values.billId = clickId;
            values.conNo = conNoId;
            values.invoiceTime = moment(values.invoiceTime).format('YYYY-MM-DD');
            ;(async () => {
                const {code, msg} = await putInvoiceInforeate(values);
                if(code === "20000") {
                    message.success('登记到账成功');
                    resetFields();
                    setAddModuleShow(false);
                }else{
                    message.error(msg);
                }
            })();
        })
    };

    const handleCancel = () => {
        resetFields();
        setAddModuleShow(false);
    };
    return <Modal 
        title="开票登记" 
        visible={addModuleShow} 
        onOk={handleOk} 
        onCancel={handleCancel}
    >
        <Form
            labelCol={{ span: 6 }}
            wrapperCol={{ span: 18 }}
            form = {form}
        >
            <Form.Item
                label="开票时间"
                name="invoiceTime"
                rules={[{ required: true, message: '请选择开票时间' }]}
            >
                <DatePicker />
            </Form.Item>
            <Form.Item
                label="发票号码"
                name="invoiceNo"
                rules={[{ required: true, message: '请输入发票号码' }]}
            >
                <Input />
            </Form.Item>
            <Form.Item
                label="发票类型"
                name="invoiceKind"
                rules={[{ required: true, message: '请选择发票类型' }]}
            >
                <Select>
                    <Option value={0} >普通发票</Option>
                    <Option value={1} >增值税专用发票</Option>
                </Select>
            </Form.Item>
            <Form.Item
                label="开票金额"
                name="invoiceMoney"
                rules={[{ required: true, message: '请输入开票金额' }]}
            >
                <InputNumber />
            </Form.Item>
        </Form>
    </Modal>
}

export default AddModule;